package exception;

import java.lang.reflect.Method;

import org.springframework.aop.ThrowsAdvice;

public class ExceptionHandler
		implements ThrowsAdvice {
	/**
	 * 对未知异常的处理.
	 * 
	 * @param method
	 * @param args
	 * @param target
	 * @param ex
	 * @throws Throwable
	 */
	public void afterThrowing(Method method, Object[] args, Object target,
			Exception ex) throws Throwable {
		System.out.println("*************************************");
		System.out.println("Error happened in class: "
				+ target.getClass().getName());
		System.out.println("Error happened in method: " + method.getName());

		for (int i = 0; i < args.length; i++) {
			System.out.println("arg[" + i + "]: " + args[i]);
		}

		System.out.println("Exception class: " + ex.getClass().getName());
		System.out.println("*************************************");
	}

	/**
	 * 对NullPointerException异常的处理
	 * 
	 * @param method
	 * @param args
	 * @param target
	 * @param ex
	 * @throws Throwable
	 * @author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a> Creation
	 *         date: 2007-7-24 - 下午01:17:35
	 */
	public void afterThrowing(Method method, Object[] args, Object target,
			NullPointerException ex) throws Throwable {
		System.out.println("*************************************");
		System.out.println("Error happened in class: "
				+ target.getClass().getName());
		System.out.println("Error happened in method: " + method.getName());

		for (int i = 0; i < args.length; i++) {
			System.out.println("args[" + i + "]: " + args[i]);
		}

		System.out.println("Exception class: " + ex.getClass().getName());
		System.out.println("*************************************");
	}
}
